<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once(APPPATH.'models/model_crud.php');

class Model_kontak extends Model_crud {

	private $id;

	private $nama;

	private $nomor;

	private $keterangan;

	private $anggota;

	public static $tabel='pbk';

	public function __construct($data) {
		$this->id = $data->pbk_id;
		$this->nama = $data->nama;
		$this->nomor = $data->nomor;
		$this->keterangan = $data->keterangan;

		model_crud::$tabel = 'pbk_relasi';
		model_crud::$tabel_join = array();

		$relasi_array = model_crud::read(array('pbk_id'=>$data->pbk_id));

		if ($relasi_array!==false)
			foreach ($relasi_array as $relasi)
				$this->anggota[] = $relasi->grup_id;
	}

	public static function read($filter = array(), $limit=array(), $select='*', $distinct=false, $group_by="", $order_by="") {

		$hasil = parent::read($filter, $limit, $select, $distinct, $group_by, $order_by);

		if ($hasil!==false){

			$objek = array();
			
			foreach ($hasil as $kontak)
				$objek[$kontak->pbk_id] = new model_kontak($kontak);

			return $objek;
		}
		else
			return false;
	}

	public function get_id(){
		return $this->id;
	}

	public function get_nama(){
		return $this->nama;
	}

	public function get_nomor(){
		return $this->nomor;
	}

	public function get_keterangan(){
		return $this->keterangan;
	}

	public function get_anggota(){
		if ($this->anggota==false)
			return array();
		else
			return $this->anggota;
	}

}